<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>编辑任务 - 威客任务平台</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
    <nav class="navbar navbar-expand-lg navbar-dark bg-dark">
        <div class="container">
            <a class="navbar-brand" href="/">威客任务平台</a>
            <div class="navbar-nav ms-auto">
                <a class="nav-link" th:href="@{/dashboard}">仪表板</a>
                <a class="nav-link" th:href="@{/admin/users}">用户管理</a>
                <a class="nav-link" th:href="@{/admin/tasks}">任务管理</a>
                <a class="nav-link" th:href="@{/logout}">退出</a>
            </div>
        </div>
    </nav>

    <div class="container mt-4">
        <h2>编辑任务</h2>
        
        <form th:action="@{/admin/tasks/update/{id}(id=${task.taskId})}" th:method="post" th:object="${task}">
            <input type="hidden" th:field="*{taskId}" />
            <!-- 保留原始发布时间和创建时间 -->
            <input type="hidden" th:field="*{publishDate}" />
            <input type="hidden" th:field="*{createTime}" />
            
            <div class="mb-3">
                <label for="employerId" class="form-label">雇主</label>
                <select class="form-control" id="employerId" th:field="*{employerId}" required>
                    <option value="">请选择雇主</option>
                    <option th:each="emp : ${employers}" th:value="${emp.userId}" 
                            th:text="${emp.username}" 
                            th:selected="${task.employerId == emp.userId}"></option>
                </select>
            </div>
            
            <div class="mb-3">
                <label for="title" class="form-label">任务标题</label>
                <input type="text" class="form-control" id="title" th:field="*{title}" required>
                <div class="text-danger" th:if="${#fields.hasErrors('title')}" th:errors="*{title}"></div>
            </div>
            
            <div class="mb-3">
                <label for="description" class="form-label">任务描述</label>
                <textarea class="form-control" id="description" th:field="*{description}" rows="5" required></textarea>
                <div class="text-danger" th:if="${#fields.hasErrors('description')}" th:errors="*{description}"></div>
            </div>
            
            <div class="mb-3">
                <label for="budget" class="form-label">任务预算</label>
                <input type="number" class="form-control" id="budget" th:field="*{budget}" step="0.01" min="0" required>
                <div class="text-danger" th:if="${#fields.hasErrors('budget')}" th:errors="*{budget}"></div>
            </div>
            
            <div class="mb-3">
                <label for="taskStatus" class="form-label">任务状态</label>
                <select class="form-control" id="taskStatus" th:field="*{taskStatus}">
                    <option value="open">待承接</option>
                    <option value="in_progress">进行中</option>
                    <option value="completed">已完成</option>
                    <option value="closed">已关闭</option>
                </select>
            </div>
            
            <div class="mb-3">
                <label for="publishDate" class="form-label">发布时间</label>
                <input type="text" class="form-control" id="publishDate" th:field="*{publishDate}" disabled>
            </div>
            
            <div class="mb-3">
                <label for="createTime" class="form-label">创建时间</label>
                <input type="text" class="form-control" id="createTime" th:field="*{createTime}" disabled>
            </div>
            
            <button type="submit" class="btn btn-primary">更新任务</button>
            <a th:href="@{/admin/tasks}" class="btn btn-secondary">返回任务列表</a>
        </form>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>